<?php

function buildTreeCategoryOption($catData, $prentsID = 0) {
    $specs = '&nbsp;';
    foreach ($catData as $aCat) {

        if ($aCat['category_parent'] == $prentsID) {
            if($aCat['category_level'] == 0){
                $style = 'style=color:#F58516;';
            }
            if ($aCat['category_level'] == 1) {
                $specs = '&nbsp;&nbsp;&nbsp;';
            }
            if ($aCat['category_level'] == 2) {
                $specs = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
            }
            if ($aCat['category_level'] == 3) {
                $specs = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
            }
            $catList .= "<option value=" . $aCat['category_id'] . "  $style>" . $specs . $aCat['category_name'] . "</option>";
            $catList .= buildTreeCategoryOption($catData, $aCat['category_id']);
        }
    }
    return $catList;
}

$strCatOption = buildTreeCategoryOption($aryCategory);
?>

<div class="search_product">
    <form name="search_product" id="search_product" onsubmit="AdminController.searchProduct('price-down', 1); return false;">
        <ul class="list_item_search">
            <li>
                Tên hoặc mã sản phẩm
            </li>
            <li>
                <input type="text" name="search_product_name" id="search_product_name" class="w200p">
            <li>
                <select name="search_category_id" id="search_category_id">
                    <option value="0">Chọn danh mục</option>
                    <?php echo $strCatOption; ?>
                </select>
            </li>
            <li>
                <input type="button" name="btn_search_product" id="btn_search_product" class="submit" value="Tìm kiếm" onclick="AdminController.searchProduct('price-down', 1);">
            </li>
        </ul>

    </form>
</div>
<div id="list_search_result">
    <div class="order">
    <div class="order-item">
        <ul>
            <li class="title-first">Sắp xếp:</li>
            <li>
                <a class="<?php echo ($orderType == 'id-down') ? 'selected' : ''; ?>" onclick="AdminController.getListProduct('id-down', '<?php echo $categoryId; ?>', 0, '<?php echo $page; ?>')">ID giảm</a>
            </li>
            <li>
                <a class="<?php echo ($orderType == 'id-up') ? 'selected' : ''; ?>" onclick="AdminController.getListProduct('id-up', '<?php echo $categoryId; ?>', 0,'<?php echo $page; ?>')">ID tăng</a>
            </li>
            <li>
                <a class="<?php echo ($orderType == 'date-down') ? 'selected' : ''; ?>" onclick="AdminController.getListProduct('date-down', '<?php echo $categoryId; ?>', 0, '<?php echo $page; ?>')">Ngày đăng giảm</a>
            </li>
            <li>
                <a class="<?php echo ($orderType == 'date-up') ? 'selected' : ''; ?>" onclick="AdminController.getListProduct('date-up', '<?php echo $categoryId; ?>', 0, '<?php echo $page; ?>')">Ngày đăng tăng</a>
            </li>
            <li>
                <a class="<?php echo ($orderType == 'price-down') ? 'selected' : ''; ?>" onclick="AdminController.getListProduct('price-down', '<?php echo $categoryId; ?>', 0,'<?php echo $page; ?>')">Giá giảm</a>
            </li>
            <li>
                <a class="<?php echo ($orderType == 'price-up') ? 'selected' : ''; ?>" onclick="AdminController.getListProduct('price-up', '<?php echo $categoryId; ?>', 0,'<?php echo $page; ?>')">Giá tăng</a>
            </li>
            <li>
                <a>Đơn hàng</a>
            </li>
        </ul>
    </div>

</div>
<div>
    <table cellpadding="0" cellspacing="0" width="100%" align="left" class="table-list">
        <col >
        <col >
        <col >
        <col >
        <col >
<?php foreach ($aryProduct as $key => $value) { ?>
        <tr class="<?php echo ($key % 2 == 0) ? 'alt' : '' ?>">

            <td class="product-img">
                <div>
                    <a href="<?php echo $root_page; ?>/product/<?php echo $value['product_id']; ?>/<?php echo $value['product_title_filter']; ?>.html">
                        <img src="<?php echo $value['product_main_image']; ?>" border="0" align="middle">
                    </a>
                </div>
            </td>
            <td>
                <div class="product-name">
                    <a  href="<?php echo $root_page; ?>/product/<?php echo $value['product_id']; ?>/<?php echo $value['product_title_filter']; ?>.html"><?php echo $value['product_title']; ?></a>
                </div>
                <div class="product-des">
<?php echo $value['product_highlight']; ?>
                </div>
            </td>
            <td class="list_product_detail">
<?php if ($value['product_price_active_km'] == 1) { ?>
                <div class="older_price">
                    Giá cũ : <?php echo number_format($value['product_price_vnd'], 0, ',', '.'); ?>&nbsp;VNĐ
                </div>
                <div>
                    Giá KM : <?php echo number_format($value['product_price_vnd_km'], 0, ',', '.'); ?>&nbsp;VNĐ
                </div>
<?php } else { ?>
                <div>
                    Giá :<?php echo number_format($value['product_price_vnd'], 0, ',', '.'); ?>&nbsp;VNĐ
                </div>
<?php } ?>

                <div>
<?php if ($value['product_is_vat'] == 1) { ?>
                    (Có VAT)
<?php } else { ?>
                    (Chưa có VAT)
<?php } ?>
                </div>
                <div>
                    Bảo hành :&nbsp;<?php echo $value['product_warranty_name']; ?>
                </div>
                <div>
                    Trong kho :&nbsp;<?php echo $value['product_store_name']; ?>
                </div>
                <div>
                    Khuyến mại :&nbsp;<?php echo $value['product_promotional']; ?>
                </div>
            </td>
            <td>
                <div>
                    Người đăng:&nbsp;<?php echo $value['product_creator_name']; ?>
                </div>
                <div>
                    Ngày đăng:&nbsp;<?php echo date('d/m/Y', strtotime($value['product_created_date']));
    ; ?>
                </div>
                <div>
                    Người cập nhật:&nbsp;<?php echo $value['product_updater_name']; ?>
                </div>
                <div>
                    Ngày cập nhật:&nbsp;<?php echo date('d/m/Y', strtotime($value['product_updated_date']));
    ; ?>
                </div>
            </td>
            <td>
                <div>
<?php if ($perProductEdit == 2 || $isMaster == 1) { ?>
                    <span class="cpointer" onclick="AdminController.editProduct('<?php echo $value['product_id']; ?>', '<?php echo $value['product_category_id']; ?>');"><img src="/public/images/form/icon-edit.gif" title="Sửa sản phẩm này"></span>
<?php } ?>
                </div>
            </td>
            <td>
                <div>
<?php if ($perProductDelete == 3 || $isMaster == 1) { ?>
                    <span class="cpointer" onclick="AdminController.deleteProduct('<?php echo $value['product_id']; ?>');"><img src="/public/images/form/delete.png" title="Xóa sản phẩm này"></span>
<?php } ?>
                </div>
            </td>
        </tr>
<?php } ?>

        </table>

    </div>
    <div class="clear"></div>
    <div align="right"><?php echo $strPaging; ?></div>
</div>
